<?php

/**
 * Created by IntelliJ IDEA.
 * User: keke
 * Date: 18-10-27
 * Time: 下午12:30
 */
// session_start();
// $uid = $_SESSION['loginflag'];
// $sql = "SELECT * FROM users WHERE uid = '$uid' ";
// $query = $conn->query($sql);
// $result = $query->fetch_array();
require_once "../lib/common.php";
require_once "../congfig/config.php";
$username = $_POST['username'];
$sql = "SELECT * FROM users WHERE username = '$username' ";
$query = $conn->query($sql);
$result = $query->fetch_array();
if(!$query){
    exit(jsoncall(-1,"无此用户"));
}
$passwd = enpasswd($_POST['newpasswd']);
$veriypasswd = enpasswd($_POST['veriypasswd']);
if ($passwd !== $veriypasswd) {
    exit(jsoncall(-1, "密码不一致"));
}

$sql = "UPDATE users SET passwd='$passwd' WHERE username = '$username'";
$query = $conn->query($sql);
if ($query) {
    exit (jsoncall(1, "修改密码成功"));
} else {
    exit (jsoncall(-1, "修改密码失败请重试"));
}